#name : fun binary power based on exact ci
# key : bin.power.exact.ci.func
# contributor: Shuguang Sun
# --
${1:binary_exact} <- function(n = 20, p0 = 0.5, p1 = 0.35, alpha = 0.025) {

## from gsDesign::nBinomial1Sample
if (p0 < p1) {
CritVal <- stats::qbinom(p = 1 - alpha, size = n, prob = p0) + 1
Power <- stats::pbinom(CritVal - 1, n, p1, lower.tail = FALSE)
} else {
CritVal <- stats::qbinom(p = alpha, size = n, prob = p0)
Power <- stats::pbinom(CritVal - 1, n, p1, lower.tail = TRUE)
}

Power
}

$1($0)